<?
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once '../_inc/class.wfmModulo.php';
require_once '../_inc/class.wfmPagina.php';

$oMod = new wfmModulo(reqVarInt('id'));
if ($oMod->codModulo == "") {
	backOnErr("id.modulo '".reqVar('id')."' errato");
	exit;
}
$idModulo = $oMod->idModulo;
$codModulo = $oMod->codModulo;

if (reqVarInt('idl')>0) {
	$sSql = "SELECT l.* "
		." FROM wfm_rec_".$codModulo."_log l "
		." WHERE l.id_log = ".reqVarInt('idl');
} else {
	$sSql = "SELECT r.* "
		." FROM wfm_rec_".$codModulo." r "
		." WHERE r.id_rec = ".reqVarInt('idr');	
}	
$objDB->exec($sSql);
$aNew = $objDB->fetch();
if (!$aNew) {
	die("id. inesistente !<br><br>$sSql");
}
$sSql = "SELECT l.* "
	." FROM wfm_rec_".$codModulo."_log l "
	." WHERE l.id_rec = ".$aNew['id_rec']
	." AND data_ora_mod <= '".$aNew['data_ora_mod']."'"
	." AND id_log <> ".reqvarInt('idl')
	." ORDER BY l.data_ora_mod DESC ";
$objDB->exec($sSql);
$aOld = $objDB->fetch();
if (!$aOld) {
	die("Nessuna registrazione precedente !<br><br>$sSql");
}

echo getTestaPopUpHtml("Dati log",$msgPag,array('width'=>500));
?>
<table width='100%' cellspacing='1' cellpadding='2' border='0'>
   <tr>
      <td class='cmd1' align='right'>
         &nbsp;&nbsp;&nbsp;
         <a href="javascript:self.close();" class='cmd1'>chiudi</a>
      </td>
   </tr>
</table>
<table width='100%' cellspacing='1' cellpadding='2' border='0'>
   <tr>
      <td  class='tit1' colspan='3' >Dati modificati</td>
   </tr>
   <tr>
      <td  class='lab1' align='center' width='20%'>Campo</td>
      <td  class='lab1' align='center' width='40%'>Nuovo valore</td>
      <td  class='lab1' align='center' width='40%'>Valore precedente</td>
<?php
foreach($aNew as $campoX => $valX) {
	if ($campoX != 'stato'
	&& $campoX != 'id_pagina'
	&& $campoX != 'id_utente_mod'
	&& $campoX != 'data_ora_mod'
	&& $valX == $aOld[$campoX]) {
		continue;
	}
?>
   <tr>
      <td  class='txt1'>
			<?php echo $campoX;?>
		</td>
      <td  class='txt1'>
         <?echo $valX;?>
      </td>
      <td  class='txt1'>
         <?echo $aOld[$campoX];?>
      </td>
   </tr>
<?php 
}
?>
</table>
<table width='100%' cellspacing='1' cellpadding='2' border='0'>
   <tr>
      <td class='cmd1' align='right' >
         &nbsp;&nbsp;&nbsp;
         <a href="javascript:self.close();" class='cmd1'>chiudi</a>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
echo getCodaPopUpHtml();
